//
// Created by Tony on 2024/5/29.
//

#ifndef RT_CODE_METHOD_H
#define RT_CODE_METHOD_H

#include "Code.h"
#include "Member.h"
#include <cstdint>

namespace RtCode {

class Method final : public Member {
    uint16_t mArgSlotCount{};
    shared_ptr<Code> mCode;
    int32_t mReturnType{};
    vector<int32_t> mParameterTypes;

public:
    explicit Method(const string& name);

    shared_ptr<Code> getCode() { return mCode; }

    void setLocalSlotCount(uint16_t maxLocals) const { mCode->setLocalSlotCount(maxLocals); }
    uint16_t getLocalSlotCount() const { return mCode->getLocalSlotCount(); }
    uint16_t getMaxStack() const { return mCode->getMaxStack(); }

    void setArgSlotCount(uint16_t argSlotCount) { this->mArgSlotCount = argSlotCount; }
    uint16_t getArgSlotCount() const { return mArgSlotCount; }

    void setType(const vector<int32_t>& parameterTypes, int32_t returnType);
    int32_t getReturnType() const { return mReturnType; }
    bool isReturnVoid() const;
    const vector<int32_t>& getParameterTypes() { return mParameterTypes; }

    string toString();
};

} // namespace RtCode

#endif // RT_CODE_METHOD_H
